package com.syf.controller.RJController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.syf.cmd.CompanyApplyCmd;
import com.syf.cmd.SelByIDCmd;
import com.syf.domain.store.BsCompanyApply;
import com.syf.model.R;
import com.syf.service.BsCompanyApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author syf
 * @create 2022-02-08 9:19
 */
@RestController
@RequestMapping("/companyApply")
@Api(tags = "软件厂商管理")
public class BsCompanyApplyController {

    @Autowired
    private BsCompanyApplyService bsCompanyApplyService;

    @PostMapping("/before/addApply")
    @CrossOrigin
    @ApiOperation(value = "新增一个软件厂商申请")
    public R add(@RequestBody @Validated BsCompanyApply bsCompanyApply){
        boolean exist = bsCompanyApplyService.checkExist(bsCompanyApply.getCompanyName());
        if(exist){
            return  R.fail("该厂商已入驻，请不要重复申请") ;
        }
        boolean save = bsCompanyApplyService.save(bsCompanyApply);
        if(save){
            return R.ok("新增成功") ;
        }
        return  R.fail("新增失败") ;
    }

    /**
     * 1、厂商入驻申请单
     *{
     *   "current": 0,
     *   "size": 10,
     *   "companyName": "",	 	//厂商名称
     *   "applyStatus": 0,     //申请状态（0申请中，1通过，2失败）
     *                           【只有为0，才有"审核按钮", 1和2 有"查看审核结果按钮" 】
     * }
     *
     * 2、厂商管理：
     *{
     *   "current": 0,
     *   "size": 10,
     *   "companyCode": "",   	//厂商代号
     *   "companyName": "",	 	//厂商名称
     *   "status": 0, 			//公司状态（0正常，1禁用，3不合法） 下拉框
     *   "applyStatus": 1      //申请状态（0申请中，1通过，2失败）【必须是1】
     * }
     *
     * @return
     */
    @PostMapping("/companyList")
    @CrossOrigin
    @ApiOperation(value = "分页条件查询--软件厂商(申请)列表【企业名称，数字签名，申请状态，企业状态】")
    public R<Page<BsCompanyApply>> findByPage(@RequestBody CompanyApplyCmd companyApplyCmd){
        Page<BsCompanyApply> pageData =  bsCompanyApplyService.findByPage(companyApplyCmd) ;
        return R.ok(pageData) ;
    }


    @PostMapping("/companyDetails")
    @CrossOrigin
    @ApiOperation(value = "查看软件厂商(申请)详细")
    public R<BsCompanyApply> applyDetails(@RequestBody SelByIDCmd selByIDCmd){
        BsCompanyApply bsCompanyApply =  bsCompanyApplyService.getById(selByIDCmd.getId()) ;
        return R.ok(bsCompanyApply) ;
    }


    @PostMapping("/updateCompany")
    @CrossOrigin
    @ApiOperation(value = "修改软件厂商信息")
    public R updateCompany(@RequestBody  BsCompanyApply bsCompanyApply){
        boolean update = bsCompanyApplyService.updateById(bsCompanyApply);
        if(update){
            return R.ok("修改成功") ;
        }
        return  R.fail("修改失败") ;
    }

    @PostMapping("/updateStatus")
    @CrossOrigin
    @ApiOperation(value = "修改软件厂商状态()")
    public R updateStatus(@RequestBody  BsCompanyApply bsCompanyApply){
        boolean update = bsCompanyApplyService.updateStatus(bsCompanyApply);
        if(update){
            return R.ok("修改成功") ;
        }
        return  R.fail("修改失败") ;
    }

}
